package com.mairuide.multipleData.controller;

import com.mairuide._frame.base.BaseController;
import com.mairuide._frame.base.ModuleCode;
import com.mairuide._frame.utils.excel.ExcelExportUtil;
import com.mairuide.common.bill.BillDetail;
import com.mairuide.common.bill.BillDetailService;
import com.mairuide.common.bill.BillSearchParam;
import com.mairuide.common.phone.PhoneRecordDeatil;
import com.mairuide.common.phone.PhoneRecordingDetailService;
import com.mairuide.common.phone.PhoneSearchParam;
import com.mairuide.entity.PageResult;
import com.mairuide.multipleData.dto.MultipleDataDto;
import com.mairuide.multipleData.pojo.MultipleDataBill;
import com.mairuide.multipleData.pojo.MultipleDataPhone;
import com.mairuide.multipleData.service.PhoneMultipleDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description
 * @auther 刘中华
 * @create 2019-06-25 10:46
 */
@Controller
@RequestMapping("/phone/multipleData")
public class PhoneMultipleDataController extends BaseController {
    @Autowired
    PhoneMultipleDataService phoneMultipleDataService;
    @Autowired
    PhoneRecordingDetailService phoneRecordingDetailService;
    @Autowired
    BillDetailService billDetailService;


    @ModuleCode(pValue = "billanalysis", value = "phoneMultipleData")
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public Object init() {
        return "/multipleData/phone/index";
    }
    //资金
    @RequestMapping(value = "zijin", method = RequestMethod.GET)
    public Object zijin() {
        return "/multipleData/phone/zijin";
    }
    //资金详情弹窗
    @RequestMapping(value = "billToPhoneDetailInit", method = RequestMethod.GET)
    public Object billToPhoneDetailInit() {
        return "/multipleData/phone/billToPhoneDetailDialog";
    }
    //通话
    @RequestMapping(value = "tonghua", method = RequestMethod.GET)
    public Object tonghua() {
        return "/multipleData/phone/tonghua";
    }
    //通话详情弹窗
    @RequestMapping(value = "phoneToBillDetailInit", method = RequestMethod.GET)
    public Object phoneToBillDetailInit() {
        return "/multipleData/phone/phoneToBillDetailDialog";
    }

    //资金交易时的通话分析
    @RequestMapping(value = "billToPhone", method = RequestMethod.POST)
    @ResponseBody
    public Object findZijinTransaction(MultipleDataDto dto){
        List<MultipleDataPhone> zijinTransaction = phoneMultipleDataService.findZijinTransaction(dto);
        return zijinTransaction;
    }
    //资金交易时的通话详情分析
    @RequestMapping(value = "billToPhoneDetail", method = RequestMethod.POST)
    @ResponseBody
    public Object findZijinTransactionDetail(PhoneSearchParam dto){
        PageResult page = phoneRecordingDetailService.search_detail(dto);
        return page;
    }
    //资金交易时的通话分析导出excel
    @RequestMapping(value = "down_billToPhone", method = RequestMethod.POST)
    @ResponseBody
    public void downZijinTransaction(MultipleDataDto dto) throws Exception{
        //第一步 得到数据
        List<MultipleDataPhone> zijinTransaction = phoneMultipleDataService.findZijinTransaction(dto);
        //第二步 下载excel
        Class clazz= MultipleDataPhone.class;
        new ExcelExportUtil(clazz).export(response,zijinTransaction,"资金交易时的通话分析.xlsx");
    }
    //资金交易时的通话分析导出excel
    @RequestMapping(value = "down_billToPhoneDetail", method = RequestMethod.POST)
    @ResponseBody
    public void downZijinTransactionDetail(PhoneSearchParam dto) throws Exception{
        //第一步 得到数据
        dto.setPage(1);
        dto.setRows(Integer.MAX_VALUE);
        PageResult page = phoneRecordingDetailService.search_detail(dto);
        List list = page.getRows();
        //第二步 下载excel
        Class clazz= PhoneRecordDeatil.class;
        new ExcelExportUtil(clazz).export(response,list,"资金交易时的通话详情分析.xlsx");
    }
    //-------------------------------------------------开始话单-----------------------------------
    //通过话单的资金交易分析
    @RequestMapping(value = "phoneToBill", method = RequestMethod.POST)
    @ResponseBody
    public Object findPhoneTransaction(MultipleDataDto dto){
        List phoneTransaction = phoneMultipleDataService.findPhoneTransaction(dto);
        return phoneTransaction;
    }
    //通过话单的资金交易分析导出excel
    @RequestMapping(value = "down_phoneToBill", method = RequestMethod.POST)
    @ResponseBody
    public void downPhoneTransaction(MultipleDataDto dto) throws Exception{
        //第一步 得到数据
        List phoneTransaction = phoneMultipleDataService.findPhoneTransaction(dto);
        //第二步 下载excel
        Class clazz= MultipleDataBill.class;
        new ExcelExportUtil(clazz).export(response,phoneTransaction,"通过话单的资金交易分析.xlsx");
    }

    //通过话单的资金交易分析详情分析
    @RequestMapping(value = "phoneToBillDetail", method = RequestMethod.POST)
    @ResponseBody
    public Object findPhoneTransactionDetail(BillSearchParam dto){
        PageResult page = billDetailService.search_detail(dto);
        return page;
    }
    //通过话单的资金交易分析详情分析
    @RequestMapping(value = "down_phoneToBillDetail", method = RequestMethod.POST)
    public void down_PhoneTransactionDetail(BillSearchParam dto) throws Exception{
        dto.setPage(1);
        dto.setRows(Integer.MAX_VALUE);
        PageResult page = billDetailService.search_detail(dto);
        List list = page.getRows();
        //第二步 下载excel
        Class clazz= BillDetail.class;
        new ExcelExportUtil(clazz).export(response,list,"通过话单的资金交易分析.xlsx");
    }
}
